#include <stdio.h>
#include <stdlib.h>

typedef  int EleType;
typedef struct  StackNode{
    EleType  data;
    struct StackNode *next;
}StackNode;

void init (StackNode **top){
    *top=NULL;
}

void pushStack(StackNode **top,EleType n){
    StackNode  *newNode=(StackNode * ) malloc(sizeof (StackNode));
    if(newNode==NULL){
        printf("新节点内存分布失败");
        return;
    }
    newNode->data=n;
    newNode->next=*top;
    *top=newNode;
}

void printStack(StackNode **top){
        if(top==NULL){
            printf("这是一个空栈");
            return;
        }
        StackNode *p=*top;
        while(p!=NULL){
            printf("%d    ",p->data);
            p=p->next;
        }
}

void manageStack(StackNode **top){
    if(top==NULL){
        printf("这是一个空栈");
        return;
    }
    StackNode *p=*top;
    int num = 0;
    while(p!=NULL){
        num+=1;
        p=p->next;
    }
    printf("%d  ",num);
}

void null(StackNode **top){
    if(top==NULL){
        printf("这是一个空栈");
        return;
    } else{
        printf("这不是空");
        return;
    }
}

void topStack(StackNode **top) {
    if (top == NULL) {
        printf("这是一个空栈");
        return;
    }
    printf("%d",(*top)->data);
}

void returnStack(StackNode **top){
    if(top==NULL){
        printf("这是一个空栈");
        return;
    }
    StackNode *p=*top;
    *top=p->next;
    free(p);
}

int main(){
    StackNode *stack;
    init(&stack);
    pushStack(&stack,10);
    pushStack(&stack,20);
    topStack(&stack);
    printStack(&stack);
    manageStack(&stack);
    returnStack(&stack);
    manageStack(&stack);
    null(&stack);
    return 0;
}